package com.prim.threadpool;

import java.util.Arrays;
import java.util.concurrent.*;

public class CallableTest {
    static ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(
            1,
            2,
            5,
            TimeUnit.SECONDS,
            new LinkedBlockingDeque<>());

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Future<Integer> submit = poolExecutor.submit(new MyCallable());
        System.out.println("callable future.get = " + submit.get());

        Future<?> submit1 = poolExecutor.submit(new MyRunnable());
        System.out.println("runnable future.get = " + submit1.get());
    }

    static class MyCallable implements Callable<Integer> {

        @Override
        public Integer call() throws Exception {
            System.out.println("callable");
            return 1001;
        }
    }

    static class MyRunnable implements Runnable {

        @Override
        public void run() {
            System.out.println("runnable");
        }
    }
}
